package net.int0r.gscore.connector;

import java.util.ArrayList;

import net.int0r.gscore.gobjects.Spot;
import net.int0r.gscore.util.GJSONObject;
import net.int0r.gscore.util.GowallaConnector;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

public class SpotListConnector {
	public static ArrayList<Spot> getSpots(double lat, double lng, int radius) {
		ArrayList<NameValuePair> urlParms = new ArrayList<NameValuePair>();
		urlParms.add(new BasicNameValuePair("lat", ""+lat));
		urlParms.add(new BasicNameValuePair("lng", ""+lng));
		urlParms.add(new BasicNameValuePair("radius", ""+radius));
		GJSONObject jsobj = GowallaConnector.getJSONObj(urlParms, "/spots");
		ArrayList<Spot> foundSpots = new ArrayList<Spot>();
		if(!jsobj.isNull("spots")) {
			try {
				JSONArray jspts = jsobj.getJSONArray("spots");
				for(int i=0; i<jspts.length(); i++) {
					Spot tmpSpot = new Spot(new GJSONObject(jspts.get(i).toString()));
					System.out.println(tmpSpot);
					foundSpots.add(tmpSpot);
				}
			}
			catch(Exception ex) {
				ex.printStackTrace();
			}
		}
		return foundSpots;
	}
	
	public SpotListConnector() {
		System.out.println(getSpots(30.2697, -97.7494, 50));
	}
	
	public static void main(String[] args) {
		new SpotListConnector();
	}
}
